﻿using System;
using System.Data;
using Model.Data;
using Model;
using DataAccess;
using BusinessLogic.BusinessRules;


namespace BusinessLogic.ClassFactory
{
    /// <summary>
    /// SectionRelationFactory 的摘要说明。
    /// </summary>
    public class SectionRelationFactory : BaseFactory
    {
        public SectionRelationFactory()
            : base()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public SectionRelationFactory(DBManager l_DBManager)
            : base(l_DBManager)
        {
        }
        public SectionRelation NewInstance()
        {
            SectionRelationAccess l_Access = new SectionRelationAccess(m_Manager);
            SectionRelation objSectionRelation = new SectionRelation(this.m_Manager, l_Access);
            objSectionRelation.NewDataSet();
            objSectionRelation.SelectRow(0);
            return objSectionRelation;
        }

        public SectionRelation CreatorBySql(string Sql)
        {
            SectionRelationAccess l_Access = new SectionRelationAccess(m_Manager);
            SectionRelation objSectionRelation = new SectionRelation(this.m_Manager, l_Access);
            DataSet l_ds = new SectionRelationData();
            if (l_Access.QueryBySql(ref l_ds, Sql) < 1)
            {
                return null;
            }
            objSectionRelation.SetDataSet(l_ds);
            objSectionRelation.SelectRow(0);
            return objSectionRelation;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="intSRID"></param>
        /// <returns></returns>
        public SectionRelation Creator(int intSRID)
        {
            SectionRelationAccess l_Access = new SectionRelationAccess(m_Manager);
            SectionRelation objSectionRelation = new SectionRelation(this.m_Manager, l_Access);
            DataSet l_ds = new SectionRelationData();
            if (l_Access.QueryByID(ref l_ds, intSRID) < 1)
            {
                return null;
            }
            objSectionRelation.SetDataSet(l_ds);
            objSectionRelation.SelectRow(0);
            return objSectionRelation;
        }

        public SectionRelation Creator()
        {
            SectionRelationAccess l_Access = new SectionRelationAccess(m_Manager);
            SectionRelation objSectionRelation = new SectionRelation(this.m_Manager, l_Access);
            DataSet l_ds = new SectionRelationData();
            if (l_Access.QueryAll(ref l_ds) < 1)
            {
                return null;

            }
            objSectionRelation.SetDataSet(l_ds);
            objSectionRelation.SelectRow(0);
            return objSectionRelation;
        }
        /// <summary>
        /// 通过源栏目ID，创建引用此栏目的对象
        /// </summary>
        /// <param name="intSTID"></param>
        /// <returns></returns>
        public SectionRelation CreateReferedSectionBySTID(int intSTID)
        {
            string strWhere = string.Format(" intObjID = {0}", intSTID);
            return CreatorBySql(strWhere);
        }
    }
}
